package org.xvergabe.forms.poc.events;

import java.io.IOException;

import org.xvergabe.xsd.forms.components.x20.Boolean;

import com.lowagie.text.DocumentException;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPCellEvent;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.pdf.RadioCheckField;

/**
 * einer {@link cell} zugefuegt bewirkt dieses Event die Darstellung einer
 * Checkbox in dieser Zelle
 * 
 * @author schiller
 * 
 */
public class PdfFieldBoolCellEvent implements PdfPCellEvent {

	Boolean field;
	
	public PdfFieldBoolCellEvent(Boolean field) {
		this.field = field;
	}

	@Override
	public void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) {
		PdfWriter writer = canvases[0].getPdfWriter();
		RadioCheckField checkbox = new RadioCheckField(writer, position, field.getId(), "");
		checkbox.setChecked(field.getValue());
		checkbox.setCheckType(RadioCheckField.TYPE_CHECK);
		
		try {
			writer.addAnnotation(checkbox.getCheckField());
		} catch (DocumentException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
}
